/*
 * Copyright (c) 2018. 玺得（深圳）科技有限公司.保留所有权利. http://www.pi-top.com/ 玺得（深圳）科技有限公司保留所有代码著作权.如有任何疑问请访问官方网站与我们联系. 代码只针对特定需求定制编码，不得在未经允许或授权的情况下对外传播扩散.恶意传播者，法律后果自行承担. 本代码仅用于pps-cloud系统.
 */
package com.pitop.serial.ctrl;

import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import java.util.List;
import java.util.HashMap;

import com.pitop.core.entity.BeanRet;
import com.pitop.core.entity.Page;
import com.pitop.core.tools.redis.RedisUtils;
import com.pitop.serial.entity.SerialNumber;
import com.pitop.serial.service.SerialNumberSV;

/**
 * 序列号 控制器
 *
 * @author pi-top
 */
@RestController
@RequestMapping("/serialNumber")
@Slf4j
@Api(value = "序列号控制器", description = "序列号控制器")
public class SerialNumberCtrl {

    @Resource
    protected RedisUtils redisUtils;

    @Resource
    private SerialNumberSV serialNumberSV;

    /**
     * 查询SerialNumber一个详情信息
     *
     * @param id           id
     * @param code         编码
     * @param testUnitCode 测试件编码
     * @param sn           序列号
     * @param snCode       序列号类型编码
     * @return BeanRet
     */
    @ApiOperation(value = "查询SerialNumber一个详情信息", notes = "查询SerialNumber一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", dataType = "java.lang.Long", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "编码", dataType = "java.lang.String", paramType = "query"),
            @ApiImplicitParam(name = "testUnitCode", value = "测试件编码", dataType = "java.lang.String", paramType = "query"),
            @ApiImplicitParam(name = "sn", value = "序列号", dataType = "java.lang.String", paramType = "query"),
            @ApiImplicitParam(name = "snCode", value = "序列号类型编码", dataType = "java.lang.String", paramType = "query")
    })
    @GetMapping(value = "/load")
    @ResponseBody
    public SerialNumber load(java.lang.Long id, java.lang.String code, java.lang.String testUnitCode, java.lang.String sn, java.lang.String snCode) {
        if (id == null) {
            return null;
        }
        if (code == null) {
            return null;
        }
        if (testUnitCode == null) {
            return null;
        }
        if (sn == null) {
            return null;
        }
        if (snCode == null) {
            return null;
        }
        SerialNumber serialNumber = serialNumberSV.load(id, code, testUnitCode, sn, snCode);
        log.info(JSON.toJSONString(serialNumber));
        return serialNumber;
    }


    /**
     * 根据条件id查询SerialNumber一个详情信息
     *
     * @param id id
     * @return BeanRet
     */
    @ApiOperation(value = "查询SerialNumber一个详情信息", notes = "查询SerialNumber一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", dataType = "java.lang.Long", paramType = "path")
    })
    @GetMapping(value = "/load/id/{id}")
    @ResponseBody
    public SerialNumber loadById(@PathVariable java.lang.Long id) {
        if (id == null) {
            return null;
        }
        SerialNumber serialNumber = serialNumberSV.loadById(id);
        log.info(JSON.toJSONString(serialNumber));
        return serialNumber;
    }

    /**
     * 根据条件code查询SerialNumber一个详情信息
     *
     * @param code 编码
     * @return BeanRet
     */
    @ApiOperation(value = "查询SerialNumber一个详情信息", notes = "查询SerialNumber一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "code", value = "编码", dataType = "java.lang.String", paramType = "path")
    })
    @GetMapping(value = "/load/code/{code}")
    @ResponseBody
    public SerialNumber loadByCode(@PathVariable java.lang.String code) {
        if (code == null) {
            return null;
        }
        SerialNumber serialNumber = serialNumberSV.loadByCode(code);
        log.info(JSON.toJSONString(serialNumber));
        return serialNumber;
    }

    /**
     * 根据条件testUnitCode查询SerialNumber一个详情信息
     *
     * @param testUnitCode 测试件编码
     * @return BeanRet
     */
    @ApiOperation(value = "查询SerialNumber一个详情信息", notes = "查询SerialNumber一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "testUnitCode", value = "测试件编码", dataType = "java.lang.String", paramType = "path")
    })
    @GetMapping(value = "/load/testUnitCode/{testUnitCode}")
    @ResponseBody
    public SerialNumber loadByTestUnitCode(@PathVariable java.lang.String testUnitCode) {
        if (testUnitCode == null) {
            return null;
        }
        SerialNumber serialNumber = serialNumberSV.loadByTestUnitCode(testUnitCode);
        log.info(JSON.toJSONString(serialNumber));
        return serialNumber;
    }

    /**
     * 根据条件sn查询SerialNumber一个详情信息
     *
     * @param sn 序列号
     * @return BeanRet
     */
    @ApiOperation(value = "查询SerialNumber一个详情信息", notes = "查询SerialNumber一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "sn", value = "序列号", dataType = "java.lang.String", paramType = "path")
    })
    @GetMapping(value = "/load/sn/{sn}")
    @ResponseBody
    public SerialNumber loadBySn(@PathVariable java.lang.String sn) {
        if (sn == null) {
            return null;
        }
        SerialNumber serialNumber = serialNumberSV.loadBySn(sn);
        log.info(JSON.toJSONString(serialNumber));
        return serialNumber;
    }

    /**
     * 根据条件snCode查询SerialNumber一个详情信息
     *
     * @param snCode 序列号类型编码
     * @return BeanRet
     */
    @ApiOperation(value = "查询SerialNumber一个详情信息", notes = "查询SerialNumber一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "snCode", value = "序列号类型编码", dataType = "java.lang.String", paramType = "path")
    })
    @GetMapping(value = "/load/snCode/{snCode}")
    @ResponseBody
    public SerialNumber loadBySnCode(@PathVariable java.lang.String snCode) {
        if (snCode == null) {
            return null;
        }
        SerialNumber serialNumber = serialNumberSV.loadBySnCode(snCode);
        log.info(JSON.toJSONString(serialNumber));
        return serialNumber;
    }


    /**
     * 查询SerialNumber信息集合
     *
     * @return 分页对象
     */
    @ApiOperation(value = "查询SerialNumber信息集合", notes = "查询SerialNumber信息集合")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
            @ApiImplicitParam(name = "id", value = "id", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "编码", paramType = "query"),
            @ApiImplicitParam(name = "testUnitCode", value = "测试件编码", paramType = "query"),
            @ApiImplicitParam(name = "sn", value = "序列号", paramType = "query"),
            @ApiImplicitParam(name = "snCode", value = "序列号类型编码", paramType = "query"),
            @ApiImplicitParam(name = "snName", value = "序列号类型名", paramType = "query")
    })
    @PostMapping(value = "/list")
    @ResponseBody
    public List<SerialNumber> list(@RequestBody @ApiIgnore SerialNumber serialNumber, Integer curPage, Integer pageSize) {
        Page<SerialNumber> page = new Page<SerialNumber>(pageSize, curPage);
        List<SerialNumber> serialNumbers = serialNumberSV.list(serialNumber, page.genRowStart(), page.getPageSize());
        int total = serialNumberSV.count(serialNumber);
        page.setTotalRow(total);
        log.info(JSON.toJSONString(page));
        return serialNumbers;
    }


    /**
     * 查询SerialNumber信息集合
     *
     * @return 分页对象
     */
    @ApiOperation(value = "查询SerialNumber信息集合", notes = "查询SerialNumber信息集合")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
            @ApiImplicitParam(name = "id", value = "id", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "编码", paramType = "query"),
            @ApiImplicitParam(name = "testUnitCode", value = "测试件编码", paramType = "query"),
            @ApiImplicitParam(name = "sn", value = "序列号", paramType = "query"),
            @ApiImplicitParam(name = "snCode", value = "序列号类型编码", paramType = "query")
    })
    @GetMapping(value = "/list/by")
    @ResponseBody
    public List<SerialNumber> listByPk(java.lang.Long id, java.lang.String code, java.lang.String testUnitCode, java.lang.String sn, java.lang.String snCode, Integer curPage, Integer pageSize) {
        Page<SerialNumber> page = new Page<SerialNumber>(pageSize, curPage);
        List<SerialNumber> serialNumbers = serialNumberSV.list(id, code, testUnitCode, sn, snCode, page.genRowStart(), page.getPageSize());
        int total = serialNumberSV.count(id, code, testUnitCode, sn, snCode);
        page.setTotalRow(total);
        log.info(JSON.toJSONString(page));
        return serialNumbers;
    }

    /**
     * 统计SerialNumber信息数量根据主键
     *
     * @return 总条数
     */
    @ApiOperation(value = " 统计SerialNumber信息数量根据主键", notes = " 统计SerialNumber信息数量根据主键")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "编码", paramType = "query"),
            @ApiImplicitParam(name = "testUnitCode", value = "测试件编码", paramType = "query"),
            @ApiImplicitParam(name = "sn", value = "序列号", paramType = "query"),
            @ApiImplicitParam(name = "snCode", value = "序列号类型编码", paramType = "query")
    })
    @GetMapping(value = "/count/by")
    @ResponseBody
    public Integer count(java.lang.Long id, java.lang.String code, java.lang.String testUnitCode, java.lang.String sn, java.lang.String snCode) {
        return serialNumberSV.count(id, code, testUnitCode, sn, snCode);
    }

    /**
     * 统计SerialNumber信息数量
     *
     * @return 总条数
     */
    @ApiOperation(value = "统计SerialNumber信息数量", notes = "统计SerialNumber信息数量")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "编码", paramType = "query"),
            @ApiImplicitParam(name = "testUnitCode", value = "测试件编码", paramType = "query"),
            @ApiImplicitParam(name = "sn", value = "序列号", paramType = "query"),
            @ApiImplicitParam(name = "snCode", value = "序列号类型编码", paramType = "query")
    })
    @PostMapping(value = "/count")
    @ResponseBody
    public Integer count(@RequestBody SerialNumber serialNumber) {
        return serialNumberSV.count(serialNumber);
    }


    /**
     * 创建SerialNumber
     *
     * @return BeanRet
     */
    @ApiOperation(value = "创建SerialNumber", notes = "创建SerialNumber")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "snName", value = "序列号类型名", paramType = "query")
    })
    @PostMapping("/build")
    @ResponseBody
    public SerialNumber build(@RequestBody @ApiIgnore SerialNumber serialNumber) {
        serialNumberSV.save(serialNumber);
        return serialNumber;
    }


    /**
     * 修改SerialNumber
     *
     * @return BeanRet
     */
    @ApiOperation(value = "修改SerialNumber", notes = "修改SerialNumber")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "编码", paramType = "query"),
            @ApiImplicitParam(name = "testUnitCode", value = "测试件编码", paramType = "query"),
            @ApiImplicitParam(name = "sn", value = "序列号", paramType = "query"),
            @ApiImplicitParam(name = "snCode", value = "序列号类型编码", paramType = "query"),
            @ApiImplicitParam(name = "snName", value = "序列号类型名", paramType = "query")
    })
    @PutMapping("/modify")
    @ResponseBody
    public SerialNumber modify(@RequestBody @ApiIgnore SerialNumber serialNumber) {
        serialNumberSV.modify(serialNumber);
        return serialNumber;
    }

    /**
     * 删除SerialNumber
     *
     * @return BeanRet
     */
    @ApiOperation(value = "删除SerialNumber", notes = "删除SerialNumber")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "编码", paramType = "query"),
            @ApiImplicitParam(name = "testUnitCode", value = "测试件编码", paramType = "query"),
            @ApiImplicitParam(name = "sn", value = "序列号", paramType = "query"),
            @ApiImplicitParam(name = "snCode", value = "序列号类型编码", paramType = "query")
    })
    @DeleteMapping("/delete")
    @ResponseBody
    public BeanRet delete(java.lang.Long id, java.lang.String code, java.lang.String testUnitCode, java.lang.String sn, java.lang.String snCode) {
        serialNumberSV.delete(id, code, testUnitCode, sn, snCode);
        return BeanRet.create(true, "删除SerialNumber成功");
    }

}
